package week_02.entertaining_diversions.two_dimensional.even;

import java.util.Arrays;

public class two_dimensional_even {
    public static void main(String[] args) {
        Integer[][] a = new Integer[5][5];
        Integer[][] a_check = new Integer[5][5];
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a.length; j++) {
                a[i][j] = i * 5 + j + 1;
            }
        }
        System.out.println("起始数组:");
        System.out.println(Arrays.deepToString(a));
        //外圈
        do {
            int temp;
            int tempN;
            temp = a[0][4];
            //让第一行的数字往右走
            for (int i = 4; i > 0; i--) {
                a[0][i] = a[0][i - 1];
            }
            //让第一列往上走
            for (int i = 0; i < 4; i++) {
                a[i][0] = a[i + 1][0];
            }
            //让第四行的数字往左走
            for (int i = 0; i < 4; i++) {
                a[4][i] = a[4][i + 1];
            }
//        让第四列的数字往下走
            for (int i = 4; i > 0; i--) {
                a[i][4] = a[i - 1][4];
            }
            a[1][4] = temp;
            //内圈
            tempN=a[1][1];
            a[1][1]=a[2][1];
            a[2][1]=a[2][2];
            a[2][2]=a[2][3];
            a[2][3]=a[3][1];
            a[3][1]=a[3][2];
            a[3][2]=a[3][3];
            a[3][3]=a[2][3];
            a[2][3]=a[1][3];
            a[1][3]=a[1][2];
            a[1][2]=tempN;
            a_check = a.clone();
            System.out.println(Arrays.deepToString(a_check));
        } while (a[0][0] != 1 || a[4][4] != 25 || a[1][1] != 7 || a[2][2] != 13);
    }
}
/*
[1  2  3  4   5]
[6  7  8  9  10]
[11 12 13 14 15]
[16 17 18 19 20]
[21 22 23 24 25]
* */